home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SunSoft Catalyst CDWARE 1996 May to August
/
Catalyst CDWARE 1996 May to August.iso
/
.products
/
SunSoft.CafeDelSol
/
ScrollMap
/
spam
< prev
Wrap
Text File
|
1996-02-01
|
15KB
|
494 lines
import java.awt.*;
import java.awt.image.*;
import java.net.*;
import java.net.MalformedURLException;
import java.util.StringTokenizer;
class ImageLoader extends Thread {
ScrollMap parent;
Image img;
ImageLoader (ScrollMap parent) {
this.parent = parent;
start();
}
public void run() {
int n = 0;
while (n < (parent.nimgs -1)) {
n++;
img = parent.getImage (parent.getDocumentBase(), parent.img_dir + "/" + parent.urlarr[n]);
if (parent.numimgarr[n] != 0) {
parent.animgarr[n] = new MyImage( parent, n, parent.numimgarr[n], parent.urlarr[n]);
}
parent.ldimage = false;
parent.add(img, n);
}
}
}
class MyImage extends Thread {
Image animg[] ;
ScrollMap parent;
String url;
int N;
int which = 1;
int skip = 0;
public void run() {
for ( int nn=1;nn < (parent.numimgarr[N] +1 );nn++) {
animg[nn] = parent.getImage (parent.getDocumentBase(), parent.img_dir + "/" + parent.urlarr[N] + nn);
if (animg[nn] == null) { break;}
}
}
MyImage ( ScrollMap parent, int n, int nimgs, String url) {
this.parent = parent;
N = n;
this.url = url;
animg = new Image[nimgs+1];
start();
}
}
public class ScrollMap extends java.applet.Applet implements Runnable {
Image offscrImg;
Graphics offscrG;
boolean onarr[];
Image imgs[];
MyImage animgarr[];
String param;
String prev;
String current;
String urlarr[] = new String [64];
String destarr[] = new String [64];
String namearr[] = new String [64];
String soundarr[] = new String [64];
int numimgarr[] = new int [64];
int skiparr[] = new int [64];
int backarr[] = new int [64];
int widtharr[] = new int [64];
int accum[] = new int [64];
int num = 1;
int n;
int pos;
int fix;
int newpos;
int nimgs;
int width;
int height;
int totalwidth = 0;
int x, newx;
int dist = 1;
int timeout = 200;
int mousepos;
Thread scroller;
String img_dir;
String showstat;
String before;
String after;
String url;
String dir;
String statuschk;
boolean ldimage = false;
boolean loaded;
boolean top;
boolean in = false;
URL anchor;
public void debug (String s) {
System.out.println(s);
}
public void init () {
String at = getParameter("before");
before = (at != null) ? at : "";
at = getParameter("after");
after = (at != null) ? at : "";
at = getParameter("img_dir");
img_dir = (at != null) ? at : "doc:/demo/images/duke";
at = getParameter("speed");
timeout = 1000 / ((at == null) ? 4 : Integer.valueOf(at).intValue());
at = getParameter("dir");
dist = (at == null) ? 5 : Integer.valueOf(at).intValue();
width = size().width;
height = size().height;
newx = x = size().width;
while (true) {
nimgs++;
urlarr[nimgs] = getParameter("url"+nimgs);
if (urlarr[nimgs] == null) { break;}
destarr[nimgs] = getParameter("dest"+nimgs);
namearr[nimgs] = getParameter("name"+nimgs);
soundarr[nimgs] = getParameter("sound"+nimgs);
if (getParameter("background"+nimgs) != null) {
backarr[nimgs] = Integer.valueOf(getParameter("background"+nimgs)).intValue();
} else {
backarr[nimgs] = 0;
}
if (getParameter("skip"+nimgs) != null) {
skiparr[nimgs] = Integer.valueOf(getParameter("skip"+nimgs)).intValue();
} else {
skiparr[nimgs] = 0;
}
if (getParameter("numimg"+nimgs) != null) {
numimgarr[nimgs] = Integer.valueOf(getParameter("numimg"+nimgs)).intValue();
} else {
numimgarr[nimgs] = 0;
}
if (urlarr[nimgs] == null) {
break;
}
}
onarr = new boolean[nimgs+1];
imgs = new Image[nimgs+1];
animgarr = new MyImage[nimgs];
//offscrImg = createImage(width, height);
//offscrG = offscrImg.getGraphics();
}
public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h) {
if ((flags & WIDTH) != 0 ) {
n++;
if (n >= (nimgs-1) ){
for (n=1;n < nimgs; n++) {
int tmpW = imgs[n].getWidth(this);
totalwidth += tmpW;
widtharr[n] = tmpW;
}
}
}
return super.imageUpdate(img, flags, x, y, w, h);
}
public void showDocument(URL u) {
getAppletContext().showDocument(u);
}
public synchronized void add(Image img, int n) {
imgs[n] = img;
if (isActive()) {
repaint();
}
}
public void start() {
if (!loaded) {
loaded = true;
new ImageLoader(this);
}
if (scroller == null) {
scroller = new Thread(this);
scroller.start();
}
}
public void stop() {
if (scroller != null) {
scroller.stop();
scroller = null;
}
}
public void run() {
while (true) {
try {Thread.currentThread().sleep(timeout);} catch (InterruptedException e){}
scroll(dist);
}
}
synchronized void scroll(int dist) {
repaint();
}
public void update(Graphics g) {
newx += dist;
g.setColor(Color.lightGray);
if (newx != x) {
int dist = newx - x;
if (dist > 0) {
for (x = newx ; x > width ; x -= Math.max(width - 2, totalwidth));
paint(g, 1, dist + 1);
} else {
for (x = newx ; x < 0 ; x += Math.max(width - 2, totalwidth));
paint(g, (width-1) + dist, width-1);
}
if ( in ) {
statusShow();
}
} else {
//paint(g);
}
}
public void paint(Graphics g, int fromx, int tox) {
paintbuffer(offscrG, fromx, tox);
g.drawImage(offscrImg, 0, 0, this);
}
public void paintbuffer(Graphics g, int fromx, int tox) {
int x = this.x;
newx = x;
fix = x;
int h = 0;
int w = 0;
int accum =0;
int tmpwidth =0;
g.setColor(Color.lightGray);
g.fillRect(1, 1, width, height-2);
g.clipRect(1, 1, width, height-2);
for (int i = 0 ; i < nimgs ; i++) {
if (imgs[i] == null) {
continue;
}
w = imgs[i].getWidth(this);
h = imgs[i].getHeight(this);
if ( numimgarr[i] != 0 ) {
if (backarr[i] != 0) {
g.drawImage(imgs[i], x, height - (h+1), this);
}
if (animgarr[i].skip == skiparr[i] ) {
animgarr[i].skip = 0;
g.drawImage(animgarr[i].animg[animgarr[i].which], (x - tmpwidth), height - (h+1), this);
animgarr[i].which++;
} else {
g.drawImage(animgarr[i].animg[animgarr[i].which], (x - tmpwidth), height - (h+1), this);
animgarr[i].skip++;
}
if (animgarr[i].which > numimgarr[i]) {
animgarr[i].which = 1;
}
} else {
g.drawImage(imgs[i], x, height - (h+1), this);
}
if ((x + w) > width) {
x -= Math.max(width - 2, totalwidth);
}
x += w;
}
/*
System.out.println( x + " ");
for (int t = 1;t<nimgs+1;t++) {
tmpwidth = widtharr[t];
accum += tmpwidth;
if (numimgarr[t] != 0) {
g.drawImage(animgarr[t].animg[animgarr[t].which], (x - tmpwidth), height - (h+1), this);
animgarr[t].which++;
if (animgarr[t].which > numimgarr[t]) {
animgarr[t].which = 1;
}
}
}
*/
}
public void paint(Graphics g) {
//offscrG.draw3DRect(0, 0, width, height, true);
paint(g, 1, width-1);
}
public void statusShow (){
showStatus( showstat ) ;
accum[0] = 0;
pos = (-fix);
newpos = ((totalwidth - fix) - (totalwidth - width));
for (int i = 0 ;i < (nimgs - 1) ; i++) {
if (pos < 0 ) {
if ((width -mousepos) < newpos) {
accum[0] = (accum[0] + widtharr[i]);
if ( (newpos - (width - mousepos)) >= (accum[0]) && (newpos - (width - mousepos ) ) <= (accum[0]+widtharr[i+1])){
current = urlarr[i+1];
if (!current.equals(prev)) { onarr[i+1] = false;} else { onarr[i+1] = true;}
if (soundarr[i+1] != null && !onarr[i+1]) { play(getCodeBase(), soundarr[i+1]);}
if (destarr[i+1] != null ) {
if (namearr[i+1] !=null ) {
showstat = "Click to select: " + namearr[i+1];
} else {
if ( destarr[i+1].equals("same")) {
showstat = "Click to select: " + urlarr[i+1];
} else {
showstat = "Click to select: " + destarr[i+1];
}
}
} else {
showstat = " ";
}
break;
}
} else {
accum[0] = (accum[0] + widtharr[i]);
if ( ( (totalwidth - fix) + mousepos >= accum[0] ) && ( (totalwidth - fix) + mousepos <= (accum[0] + widtharr[i+1]) ) ) {
current = urlarr[i+1];
if (!current.equals(prev)) { onarr[i+1] = false;} else { onarr[i+1] = true;}
if (soundarr[i+1] != null && !onarr[i+1]) { play(getCodeBase(), soundarr[i+1]);}
if (destarr[i+1] != null) {
if (namearr[i+1] != null ) {
showstat = "Click to select: " + namearr[i+1];
} else {
if ( destarr[i+1].equals("same")) {
showstat = "Click to select: " + urlarr[i+1];
} else {
showstat = "Click to select: " + destarr[i+1];
}
}
} else {
showstat = " ";
}
break;
}
}
} else {
accum[0] = (accum[0] + widtharr[i]);
if ( (pos + mousepos) >= (accum[0]) && (pos + mousepos ) <= (accum[0]+widtharr[i+1])){
current = urlarr[i+1];
if (!current.equals(prev)) { onarr[i+1] = false;} else { onarr[i+1] = true;}
if (soundarr[i+1] != null && !onarr[i+1]) { play(getCodeBase(), soundarr[i+1]);}
if (destarr[i+1] != null) {
if (namearr[i+1] != null ) {
showstat = "Click to select: " + namearr[i+1];
} else {
if ( destarr[i+1].equals("same") ) {
showstat = "Click to select: " + urlarr[i+1];
} else {
showstat = "Click to select: " + destarr[i+1];
}
}
} else {
showstat = " ";
}
break;
}
}
}
prev = current;
return;
}
public boolean handleEvent(Event evt) {
boolean mouse = true;
if (evt.id == Event.MOUSE_DOWN) {
int mdx = evt.x;
accum[0] = 0;
pos = (-fix);
newpos = ((totalwidth - fix) - (totalwidth - width));
for (int i = 0 ;i < (nimgs -1) ; i++) {
if (pos < 0 ) {
if ((width -mdx) < newpos) {
accum[0] = (accum[0] + widtharr[i]);
if ( (newpos - (width - mdx)) >= (accum[0]) && (newpos - (width - mdx ) ) <= (accum[0]+widtharr[i+1])){
if ( destarr[i+1] == null ) { continue; }
if ( destarr[i+1].equals("same") ) {
try {
anchor = new URL(null, before + urlarr[i+1] + after);
} catch (MalformedURLException e) {
anchor = null;
}
} else {
try {
anchor = new URL(null, destarr[i+1]);showStatus("Fetching ...");showDocument(anchor);
} catch (MalformedURLException e) {
anchor = null;
}
}
break;
}
} else {
accum[0] = (accum[0] + widtharr[i]);
if ( ( (totalwidth - fix) + mdx >= accum[0] ) && ( (totalwidth - fix) + mdx <= (accum[0] + widtharr[i+1]) ) ) {
if ( destarr[i+1] == null ) { continue; }
if ( destarr[i+1].equals("same") ) {
try {
anchor = new URL(null, before + urlarr[i+1] + after);showStatus("Fetching ...");showDocument(anchor);
} catch (MalformedURLException e) {
anchor = null;
}
} else {
try {
anchor = new URL(null, destarr[i+1]);showStatus("Fetching ...");showDocument(anchor);
} catch (MalformedURLException e) {
anchor = null;
}
}
break;
}
}
} else {
accum[0] = (accum[0] + widtharr[i]);
if ( (pos + mdx) >= (accum[0]) && (pos + mdx ) <= (accum[0]+widtharr[i+1])){
if ( destarr[i+1] == null ) { continue; }
if ( destarr[i+1].equals("same") ) {
try {
anchor = new URL(null, before + urlarr[i+1] + after);showStatus("Fetching ...");showDocument(anchor);
} catch (MalformedURLException e) {
anchor = null;
}
} else {
try {
anchor = new URL(null, destarr[i+1]);showStatus("Fetching ...");showDocument(anchor);
} catch (MalformedURLException e) {
anchor = null;
}
}
break;
}
}
}
}
if (evt.id == Event.MOUSE_MOVE) {
in = true;
mousepos = evt.x;
}
if (evt.id == Event.MOUSE_EXIT) {
showStatus( " ") ;
in = false;
}
return mouse;
}
}